﻿@using NewLife.Common;
@using NewLife.Cube.WebMiddleware;
@using NewLife.Cube.Charts;
@{
    Layout = null;

    var set = NewLife.Cube.Setting.Current;
    var user = ViewBag.User as IUser ?? User.Identity as IUser;
    var roleNames = "";
    if (user != null) roleNames = user.Roles == null ? "" : user.Roles.Join();

    var title = ViewBag.Title + "";
    if (set.TitlePrefix && title != "" && !title.Contains(" - "))
    {
        title += " - " + NewLife.Common.SysConfig.Current.DisplayName;
    }

    var res = set.ResourceUrl;
    if (String.IsNullOrEmpty(res)) res = "/Content";
    res = res.TrimEnd('/');

    var pageSetting = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;

    var menu = ViewBag.Menu as IMenu;

    var dbclickEnable = pageSetting.EnableTableDoubleClick;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->

    <title>@title</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

    <!-- 页面内联样式 -->
    @RenderSection("css", required: false)

    <link rel="stylesheet" href="@res/adminlte/css/fontawesome-all.min.css" />
    <link rel="stylesheet" href="@res/adminlte/css/adminlte.min.css" />

    <!-- jQuery -->
    <script src="@res/js/jquery-3.6.0.min.js"></script>
</head>
<body class="hold-transition sidebar-mini">
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        @if (pageSetting.EnableNavbar)
        {
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1>@menu.DisplayName</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                @await Html.PartialAsync("_Layout_Nav")
                            </ol>
                        </div>
                    </div>
                </div><!-- /.container-fluid -->
            </section>
        }

        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                @RenderBody()
            </div>
            <!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    @if (pageSetting.EnableFooter)
    {
        @await Html.PartialAsync("_Layout_Footer")
    }

    <!-- Bootstrap 4 -->
    <script src="@res/adminlte/js/bootstrap.bundle.min.js"></script>
    <!-- AdminLTE -->
    <script src="@res/adminlte/js/adminlte.min.js"></script>
    @if (set != null && set.BootstrapSelect)
    {
        <script src="@res/bootstrap/js/bootstrap-multiselect.min.js"></script>
    }

    @RenderSection("scripts", required: false)

    <!--日历控件支持-->
    <script src="@res/DateTimePicker/bootstrap-datetimepicker.min.js"></script>
    <script src="@res/DateTimePicker/locales/bootstrap-datetimepicker.zh_CN.js"></script>
    <script>
        $(function () {
            $('.form_datetime').each(function () {
                var df = $(this).attr('dateformat');
                if (!df) {
                    $(this).attr('dateformat', 'yyyy-mm-dd hh:ii:ss');
                    $(this).width(140);
                }
                else {
                    // 把C#标准格式化替换为控件格式
                    df = df.replace('mm', 'ii').replace('MM', 'mm').replace('HH', 'hh');
                    $(this).attr('dateformat', df);

                    // 根据时间日期格式，锁定日期输入框宽度
                    if (df.indexOf('hh') >= 0)
                        $(this).width(140);
                    else
                        $(this).width(80);
                }

                //根据日期格式自动推算日期选择view显示的范围
                var sv = 2;
                var mv = 2;
                var autoView = $(this).attr('autoView');
                if (autoView != 'false') {
                    df = $(this).attr('dateformat');
                    if (df.indexOf('ii') >= 0) {
                        mv = 0;
                        if (df.indexOf('dd') >= 0) {
                            sv = 2;
                        } else {
                            sv = 1;
                        }
                    } else if (df.indexOf('hh') >= 0) {
                        mv = 1;
                        if (df.indexOf('dd') >= 0) {
                            sv = 2;
                        } else {
                            sv = 1;
                        }
                    } else if (df.indexOf('dd') >= 0) {
                        mv = 2;
                        sv = 2;
                    } else if (df.indexOf('mm') >= 0) {
                        mv = 3;
                        sv = 3;
                    } else if (df.indexOf('yyyy') >= 0) {
                        mv = 4;
                        sv = 4;
                    }
                }

                $(this).attr('startview', sv);
                $(this).attr('minview', mv);
            });
            $("[dateformat]").each(function () {
                $(this).datetimepicker({
                    format: $(this).attr("dateformat"),
                    autoclose: true,
                    language: "zh-CN",
                    forceParse: false,
                    startView: parseInt($(this).attr('startview')),
                    minView: parseInt($(this).attr('minview'))
                });
            });
        @if (set != null && set.BootstrapSelect)
        {
            <text>
                    $('.multiselect').each(function () {
                        $(this).multiselect({
                            // 下拉列表仅在列表项比较多时显示过滤框
                            enableFiltering: $(this).children().length > 10,
                            buttonClass: 'btn btn-white btn-primary',
                            templates: {
                                button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"></button>',
                                ul: '<ul class="multiselect-container dropdown-menu"></ul>',
                                filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="fa fa-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
                                filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default btn-white btn-grey multiselect-clear-filter" type="button"><i class="fa fa-times-circle red2"></i></button></span>',
                                li: '<li><a href="javascript:void(0);"><label></label></a></li>',
                                divider: '<li class="multiselect-item divider"></li>',
                                liGroup: '<li class="multiselect-item group"><label class="multiselect-group"></label></li>'
                            },
                            filterPlaceholder: '搜索',
                            nonSelectedText: '无',
                            allSelectedText: '全选'
                        });
                    });
            </text>
        }
        @*双击跳转到form
                _List_Data_Action.cshtml变更
                @Html.ActionLink("编辑", "Edit", new { id = @Model },new{@class="editcell"})*@

        @if (!dbclickEnable)
        {
            <text>
                    $('tr').dblclick(function () {
                        var $this = $(this);
                        var row = $this.closest("tr");
                        var findcell = row.find('.editcell');
                        if (findcell.length > 0) window.location.href = findcell.attr("href");
                    });
            </text>
        }
                });
    </script>

    <!--开关插件-->
    <script src="@res/bootstrap_switch/bootstrap-switch.min.js"></script>
    <script>
        $(function () {
            $("input.chkSwitch").bootstrapSwitch();
        })
    </script>
</body>
</html>